﻿#ifndef FACEMODULE_H
#define FACEMODULE_H

#include <QObject>
#include <QtSerialPort/QSerialPort>



class FaceModule : public QObject
{
    Q_OBJECT
public:
    explicit FaceModule(QObject *parent = nullptr);
    bool openSerialPort(qint32 baudRate, QString &errInfo);

    void onSendCommand(uint8_t mid, void *param, int paramSize);
    void onParseReply();

signals:
    void sigShowMsg(QString msg);
    void sigGetStatus(uint8_t status, QString errInfo, bool flag);
    void sigVerify(uint16_t userId, QString errInfo, bool flag); //通知上层解锁成功or失败.
    void sigEnroll(uint16_t userId, QString errInfo, bool flag); //通知上层注册成功or失败.
    void sigDeleteAllUser(QString errInfo, bool flag);  //通知外层已删除所有用户.
    void sigGetAllUserId(QByteArray useId, uint8_t userCnt, QString errInfo, bool flag);  //通知外层已删除所有用户.

private:
    QString getStatusStr(uint8_t status);
    QString getCmdStr(uint8_t mid);
    QString getResultStr(uint8_t result);
    QString getFaceStatuStr(uint8_t status);
    void modifyParityCheck(QByteArray &cmd);

private:
    QSerialPort *m_serial {nullptr};
    QByteArray m_buffer;
};

#endif // FACEMODULE_H
